home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxbcache.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.4 KB  |  125 lines

  1. /* Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxbcache.h,v 1.2 2000/09/19 19:00:33 lpd Exp $ */
  20. /* Bitmap cache structures */
  21.  
  22. #ifndef gxbcache_INCLUDED
  23. #  define gxbcache_INCLUDED
  24.  
  25. #include "gxbitmap.h"
  26.  
  27. /*
  28.  * These structures are superclasses for a cache in which the 'value' is
  29.  * a bitmap.  The structures defined here don't take any position about
  30.  * the nature of the 'key'.
  31.  */
  32.  
  33. /* ---------------- Bitmap cache entry ---------------- */
  34.  
  35. /*
  36.  * The cache may contain both used and free blocks.
  37.  * All blocks have a common header; free blocks have ONLY the header.
  38.  */
  39. typedef struct gx_cached_bits_head_s {
  40.     uint size;            /* total block size in bytes */
  41.     uint depth;            /* bits per pixel, free block if 0 */
  42. } gx_cached_bits_head;
  43.  
  44. #define cb_head_is_free(cbh) ((cbh)->depth == 0)
  45. #define cb_head_set_free(cbh) ((cbh)->depth = 0)
  46. #define gx_cached_bits_common\
  47.     gx_cached_bits_head head;    /* must be first */\
  48.         /* The rest of the entry is an abbreviation of */\
  49.         /* gx_strip_bitmap, sans data. */\
  50.     ushort width, height, shift;\
  51.     ushort raster;\
  52.     gx_bitmap_id id
  53. /* Define aliases for head members. */
  54. #define cb_depth head.depth
  55. /* Define aliases for common members formerly in the head. */
  56. #define cb_raster raster
  57. typedef struct gx_cached_bits_s {
  58.     gx_cached_bits_common;
  59. } gx_cached_bits;
  60.  
  61. #define cb_is_free(cb) cb_head_is_free(&(cb)->head)
  62. /*
  63.  * Define the alignment of the gx_cached_bits structure.  We must ensure
  64.  * that an immediately following bitmap will be properly aligned.
  65.  */
  66. #define align_cached_bits_mod\
  67.   (max(align_bitmap_mod, max(arch_align_ptr_mod, arch_align_long_mod)))
  68.  
  69. /*
  70.  * We may allocate a bitmap cache in chunks, so as not to tie up memory
  71.  * prematurely if it isn't needed (or something else needs it more).
  72.  * Thus there is a structure for managing an entire cache, and another
  73.  * structure for managing each chunk.
  74.  */
  75. typedef struct gx_bits_cache_chunk_s gx_bits_cache_chunk;
  76. struct gx_bits_cache_chunk_s {
  77.     gx_bits_cache_chunk *next;
  78.     byte *data;            /* gx_cached_bits_head * */
  79.     uint size;
  80.     uint allocated;        /* amount of allocated data */
  81. };
  82.  
  83. /* ---------------- Bitmap cache ---------------- */
  84.  
  85. #define gx_bits_cache_common\
  86.     gx_bits_cache_chunk *chunks;    /* current chunk in circular list */\
  87.     uint cnext;            /* rover for allocating entries */\
  88.                     /* in current chunk */\
  89.     uint bsize;            /* total # of bytes for all entries */\
  90.     uint csize        /* # of entries */
  91. typedef struct gx_bits_cache_s {
  92.     gx_bits_cache_common;
  93. } gx_bits_cache;
  94.  
  95. /* ---------------- Procedural interface ---------------- */
  96.  
  97. /* ------ Entire cache ------ */
  98.  
  99. /* Initialize a cache.  The caller must allocate and initialize */
  100. /* the first chunk. */
  101. void gx_bits_cache_init(P2(gx_bits_cache *, gx_bits_cache_chunk *));
  102.  
  103. /* ------ Chunks ------ */
  104.  
  105. /* Initialize a chunk.  The caller must allocate it and its data. */
  106. void gx_bits_cache_chunk_init(P3(gx_bits_cache_chunk *, byte *, uint));
  107.  
  108. /* ------ Individual entries ------ */
  109.  
  110. /* Attempt to allocate an entry.  If successful, set *pcbh and return 0. */
  111. /* If there isn't enough room, set *pcbh to an entry requiring freeing, */
  112. /* or to 0 if we are at the end of the chunk, and return -1. */
  113. int gx_bits_cache_alloc(P3(gx_bits_cache *, ulong, gx_cached_bits_head **));
  114.  
  115. /* Shorten an entry by a given amount. */
  116. void gx_bits_cache_shorten(P4(gx_bits_cache *, gx_cached_bits_head *,
  117.                   uint, gx_bits_cache_chunk *));
  118.  
  119. /* Free an entry.  The caller is responsible for removing the entry */
  120. /* from any other structures (like a hash table). */
  121. void gx_bits_cache_free(P3(gx_bits_cache *, gx_cached_bits_head *,
  122.                gx_bits_cache_chunk *));
  123.  
  124. #endif /* gxbcache_INCLUDED */
  125.